﻿using System;
using System.Collections;

namespace Chess_Model
{

    public class Bishop : Piece
    {
        /* MInh's test main hahahhaahahhaha
        static void Main(string[] args)
        {
            Console.WriteLine("HELLO");
            Position temp = new Position(1, 0);
            Pawn one = new Pawn(temp, 1);
            one.getNextLegalMoves();
        }*/

        //Constructor takes position
        public Bishop(Position position, int play)
        {
            pos     = position;
            player  = play;
        }

        // Generates a list of new legal positions from the current position
        // regardless of the other pieces' positions
        public override ArrayList getNextLegalMoves()
        {
            ArrayList positions = new ArrayList();

            Position newPosition;

            //NorthEast
            for (int i = 1; i < ChessBoard.X_RANGE;i++)
            {
                newPosition    = new Position(pos.x, pos.y);

                newPosition.x += i;
                newPosition.y += i;

                if(ChessUtilities.isInRange(newPosition.x, newPosition.y))
                {
                    positions.Add(newPosition);
                }
            }
            
            //SouthEast
            for (int i = 1; i < ChessBoard.X_RANGE; i++)
            {
                newPosition    = new Position(pos.x, pos.y);

                newPosition.x += i;
                newPosition.y -= i;

                if (ChessUtilities.isInRange(newPosition.x, newPosition.y))
                {
                    positions.Add(newPosition);
                }
            }

            //NorthWest
            for (int i = 1; i < ChessBoard.X_RANGE; i++)
            {
                newPosition    = new Position(pos.x, pos.y);

                newPosition.x -= i;
                newPosition.y += i;

                if (ChessUtilities.isInRange(newPosition.x, newPosition.y))
                {
                    positions.Add(newPosition);
                }
            }

            //SouthWest
            for (int i = 1; i < ChessBoard.X_RANGE; i++)
            {
                newPosition    = new Position(pos.x, pos.y);

                newPosition.x -= i;
                newPosition.y -= i;

                if (ChessUtilities.isInRange(newPosition.x, newPosition.y))
                {
                    positions.Add(newPosition);
                }
            }
            return positions;
        }

        public override String toString()
        {
            return String.Format("{0}{1}", "B", player);

        }
        

    }

}
